package com.example.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.result.Result;
import com.example.common.result.YiFeiException;
import com.example.entity.dto.PojoDto;
import com.example.entity.hz.IBody;
import com.example.entity.hz.IHead;
import com.example.entity.vo.AddFirstInspectionXianChangNoInsertVo;
import com.example.entity.vo.pc.MoctyPlus;
import com.example.entity.yifei.*;
import com.example.enums.InspectStatusEnum;
import com.example.exception.BaseException;
import com.example.exception.CustomException;
import com.example.mapper.*;
import com.example.service.*;
import com.example.service.pc.ResourceService;
import com.example.untils.BeanUtils;
import com.example.untils.LanguageConversionUtils;
import com.example.untils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class QmsmgServiceImpl extends ServiceImpl<QmsmgMapper, Qmsmg> implements QmsmgService {

    @Resource
    private CmsmdService cmsmdService;
    @Resource
    private QmsmgMapper qmsmgMapper;
    @Resource
    private CmsmwMapper cmsmwMapper;
    @Resource
    private InvmbMapper invmbMapper;
    @Resource
    private CmsmxService cmsmxService;
    @Resource
    private NgreasonService ngreasonService;
    @Resource
    private IHeadService iHeadService;
    @Autowired
    private MoclogService moclogService;
    @Resource
    private IBodyService iBodyService;
    @Resource
    private MoctyMapper moctyMapper;
    @Autowired
    private ZnxService znxService;
    @Autowired
    private IHeadMapper iHeadMapper;

    @Resource
    private ResourceService resourceService;

    @Override
    public Result queryPage(PojoDto pojoDto) {
      try {
          Map<String,Object> map =new HashMap<>();
          IPage<Qmsmg> iPage = new Page<>(pojoDto.getCurrent(),pojoDto.getSize());
          QueryWrapper<Qmsmg> qmsmgQueryWrapper = new QueryWrapper<>();
          if (StringUtils.isNotBlank(pojoDto.getPh())){
              qmsmgQueryWrapper.like("MG002",pojoDto.getPh());
          }
          if (StringUtils.isNotBlank(pojoDto.getFs())){
              qmsmgQueryWrapper.eq("MG020",pojoDto.getFs());
          }
          if (StringUtils.isNotBlank(pojoDto.getGy())){
              qmsmgQueryWrapper.eq("MG008",pojoDto.getGy());
          }
          IPage<Qmsmg> qmsmgIPage = this.qmsmgMapper.selectPage(iPage, qmsmgQueryWrapper);
          map.put("page",qmsmgIPage.getPages());
          map.put("data",qmsmgIPage.getRecords());
          map.put("total",qmsmgIPage.getTotal());
          return Result.ok(map);
      }catch (Exception e){
          throw new YiFeiException(500,"分页发生异常");
      }
    }

    @Override
    @Transactional
    public Result insert(List<Qmsmg> qmsmgList) {
        try{
            qmsmgList.stream().forEach(arr -> {
                arr.setMG001("1"+SerialNumber(arr.getMG002()));
                arr.setMG003(SerialNumber(arr.getMG002()));
                this.qmsmgMapper.insert(arr);
            });
            return Result.ok("新增成功");
        }catch (Exception e){
            throw new YiFeiException(500,e.getMessage());
        }
    }

    @Override
    public Result update(Qmsmg qmsmg) {
        try{
            int update = this.qmsmgMapper.update(qmsmg, new QueryWrapper<Qmsmg>().eq("MG002", qmsmg.getMG002()).
                    eq("MG003", qmsmg.getMG003()).eq("MG001",qmsmg.getMG001()));
            if (update>0){
                return Result.ok("修改成功");
            }
            return Result.fail("修改失败");
        }catch (Exception e){
            throw new YiFeiException(500,"修改失败:"+e.getMessage());
        }
    }

    @Override
    public Result delete(String MG002, String MG003) {
        try{
            int delete = this.qmsmgMapper.delete(new QueryWrapper<Qmsmg>().eq("MG002",MG002).
                    eq("MG003", MG003));
            if (delete>0){
                return Result.ok("删除成功");
            }
            return Result.fail("删除失败");
        }catch (Exception e){
            throw new YiFeiException(500,"删除失败:"+e.getMessage());
        }
    }

    @Override
    public Result<Qmsmg> queryXq(String MG002, String MG003) {
        try{
            Qmsmg qmsmg = this.qmsmgMapper.selectOne(new QueryWrapper<Qmsmg>().eq("MG002", MG002).
                    eq("MG003", MG003));
            return Result.ok(qmsmg);
        }catch (Exception e){
            throw new YiFeiException(500,"查询失败:"+e.getMessage());
        }
    }

    @Override
    @Transactional
    public Result getExcels(MultipartFile file, HttpServletResponse response) throws IOException {
        try{
            InputStream inputStream = file.getInputStream();
            List<Qmsmg> lists = new ArrayList<>();
            EasyExcel.read(inputStream, Qmsmg.class, new PageReadListener<Qmsmg>(lists::addAll)).sheet().doRead();
            if (!lists.isEmpty()){
                lists.forEach((arr) -> {
                    if (arr.getMG002()==null){
                        throw new YiFeiException(500,"第"+lists.indexOf(arr)+"行"+"品号不能为空");
                    }
                    if (arr.getMG008()==null){
                        throw new YiFeiException(500,"第"+lists.indexOf(arr)+"行"+"工艺编号不能为空");
                    }
                    arr.setMG001("1"+Integer.valueOf(SerialNumber(arr.getMG002()))+Integer.valueOf((lists.indexOf(arr)+1)));
                    arr.setMG003(String.valueOf(Integer.valueOf(SerialNumber(arr.getMG002()))+Integer.valueOf((lists.indexOf(arr)+1))));
                    Invmb querys = this.invmbMapper.querys(arr.getMG002());
                    if (querys!=null){
                        if (querys.getMb002()!=null){
                            arr.setUDF10(querys.getMb002());
                        }
                        if (querys.getMb003()!=null){
                            arr.setUDF11(querys.getMb003());
                        }
                    }else {
                        throw new YiFeiException(500,"第"+lists.indexOf(arr)+"行,"+arr.getMG002()+"品号错误,无法批量新增!") ;
                    }
                    Cmsmw querys1 = this.cmsmwMapper.querys(arr.getMG008());
//                    System.out.println("测试："+querys1);
                    if (querys1!=null){
                        if (querys1.getMw002()!=null){
                            arr.setUDF09(querys1.getMw002());
                        }
                        if (querys1.getMw003()!=null){
                            arr.setUDF08(querys1.getMw003());
                        }
                    }else {
                        throw new YiFeiException(500,"第"+lists.indexOf(arr)+"行,"+arr.getMG008()+"工艺编号错误,无法批量新增!") ;
                    }
                    if(arr.getMG011()!=null){
                        if (arr.getMG011().equals("文本型")){
                            arr.setMG011("4");
                        }else {
                            arr.setMG011("3");
                        }
                    }
                    if(arr.getMG009()!=null){
                        if (arr.getMG009().equals("计数")){
                            arr.setMG009("1");
                        }else {
                            arr.setMG009("2");
                        }
                    }
                    if(arr.getMG015()!=null){
                        if (arr.getMG015().equals("依抽查基础")){
                            arr.setMG015("1");
                        }else {
                            arr.setMG015("2");
                        }
                    }
                });
            }
            boolean b = this.saveBatch(lists);
            if (b){
                return Result.ok("导入成功");
            }
            return Result.fail(lists);
//            return Result.ok(lists);
        }catch (Exception e){
            throw new YiFeiException(500,"Excel表格导入发生异常"+e.getMessage());
        }
    }

    @Override
    public Result checkExcel(MultipartFile file, HttpServletResponse response) {
        try{
            InputStream inputStream = file.getInputStream();
            List<Qmsmg> lists = new ArrayList<>();
            EasyExcel.read(inputStream, Qmsmg.class, new PageReadListener<Qmsmg>(lists::addAll)).sheet().doRead();
            List<Qmsmg> insList = new ArrayList<>();
            List<Invmb> invmbList = invmbMapper.selectList(null);
            Map<String, String> invmbMap = new HashMap<>();
            for(Invmb invmb : invmbList) {
                invmbMap.put(invmb.getMb001().trim(), "1");
            }
            if (!lists.isEmpty()){
                for(Qmsmg arr : lists) {
                    if(invmbMap.get(arr.getMG002().trim()) == null) {
                        insList.add(arr);
                    }
                }
            }

            // 写法1 JDK8+
            // since: 3.0.0-beta1
            String fileName = "品号不存在" + System.currentTimeMillis() + ".xlsx";
            // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
            // 如果这里想使用03 则 传入excelType参数即可
            EasyExcel.write(fileName, Qmsmg.class)
                    .sheet("模板")
                    .doWrite(() -> {
                        // 分页查询数据
                        return insList;
                    });

            return Result.ok();
        }catch (Exception e){
            throw new YiFeiException(500,"Excel表格导入发生异常"+e);
        }
    }

    @Override
    public Result exportExcel() {
        // 写法1 JDK8+
        // since: 3.0.0-beta1
        List<Qmsmg> qmsmgList = qmsmgMapper.selectList(new LambdaQueryWrapper<Qmsmg>().eq(Qmsmg::getMG020, "首检"));
        String fileName = "现系统首检资料" + System.currentTimeMillis() + ".xlsx";
        // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, Qmsmg.class)
                .sheet("模板")
                .doWrite(() -> {
                    // 分页查询数据
                    return qmsmgList;
                });

        List<Qmsmg> aa = qmsmgMapper.selectList(new LambdaQueryWrapper<Qmsmg>().eq(Qmsmg::getMG020, "过程检验"));
        fileName = "现系统过程检验资料" + System.currentTimeMillis() + ".xlsx";
        // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, Qmsmg.class)
                .sheet("模板")
                .doWrite(() -> {
                    // 分页查询数据
                    return aa;
                });
        return Result.ok();
    }

    // MG008   MG010
    @Override
    @Transactional
    public Result getExcels2(MultipartFile file, HttpServletResponse response, String zhi) throws IOException {
        try{
            InputStream inputStream = file.getInputStream();
            List<Qmsmg> lists = new ArrayList<>();
            EasyExcel.read(inputStream, Qmsmg.class, new PageReadListener<Qmsmg>(lists::addAll)).sheet().doRead();
//            System.out.println("123456"+lists);
            List<Qmsmg> insertList = new ArrayList<>();
             if (!lists.isEmpty()){
                for(Qmsmg arr : lists) {
//                    arr.set(arr, LanguageConversionUtils.convertToSimplifiedChinese(arr));
                    arr = LanguageConversionUtils.convertToSimplifiedChinese(arr);
                    Integer count = qmsmgMapper.selectCount(new LambdaQueryWrapper<Qmsmg>().eq(Qmsmg::getMG002, arr.getMG002()).eq(Qmsmg::getMG020, zhi));
                    if(count == null || count == 0) {
                        System.out.println("新增的品号" + arr.getMG002());
                        arr.setCREATOR("ERP");
                        arr.setCREATE_DATE(TimeUtils.getNowTime());
                        arr.setMG010("Y");
                        arr.setMG015("1");
                        arr.setMG016(new BigDecimal(0));
                        arr.setMG017("N");
                        arr.setMG001(arr.getMG003());
                        if(arr.getMG011()!=null){
                            if (arr.getMG011().equals("计数")){
                                arr.setMG011("4");
                            }else {
                                arr.setMG011("3");
                            }
                        }
                        if(arr.getMG009()!=null){
                            if (arr.getMG009().equals("计数")){
                                arr.setMG009("1");
                            }else {
                                arr.setMG009("2");
                            }
                        }
                        insertList.add(arr);
//                        qmsmgMapper.insert(arr);
                    }
                }
            }
//            for(Qmsmg t : lists) {
//                System.out.println(t);
//                this.save(t);
//            }
            boolean b = this.saveBatch(insertList);
            if (b){
                return Result.ok("导入成功");
            }
            return Result.fail();
//            return Result.ok();
        }catch (Exception e){
            throw new YiFeiException(500,"Excel表格导入发生异常"+e);
        }
    }

    @Override
    public Integer addFirstInspectionXianChang(String uuid, String jinzhanUuid) {

        MoctyPlus moctyPlus = moctyMapper.getMoctyPlus(uuid);
        QueryWrapper<Qmsmg> qmsmgQueryWrapper = new QueryWrapper<>();
        qmsmgQueryWrapper.eq("MG002", moctyPlus.getProductId());// 品号
        qmsmgQueryWrapper.eq("MG020", "首检"); //检验项目
//        qmsmgQueryWrapper.last("AND UDF06 = '现场'");
//        if (!StringUtils.isBlank(pojo.getRomm())){
//            qmsmgQueryWrapper.eq("UDF06", pojo.getRomm()); // 场地
//        }
        List<Qmsmg> qmsmgs = qmsmgMapper.selectList(qmsmgQueryWrapper);
        if (qmsmgs.isEmpty()) {  //没有首检项目，可直接上机
            return 0;
        }

//        DynamicDataSourceContextHolder.push("mes");
        com.example.entity.mysql.Resource resource = resourceService.getOne(new LambdaQueryWrapper<com.example.entity.mysql.Resource>()
                .eq(com.example.entity.mysql.Resource::getResourceGroupIdIsF, moctyPlus.getTy009()));
        if(resource == null) {
            throw new CustomException("500", "机器不存在");
        }

//        DynamicDataSourceContextHolder.push("demo");
        Map<String, List<Qmsmg>> map = new HashMap<>();
        List<Qmsmg> qmsmgList = new ArrayList<>();
        for(Qmsmg t : qmsmgs) {
            qmsmgList.add(t);
        }
        map.put("现场", qmsmgList);
        List<IHead> iHeadList = new ArrayList<>();
        List<IBody> iBodyList = new ArrayList<>();
        for (Map.Entry<String, List<Qmsmg>> entry : map.entrySet()) {  // 按检验场别生成多张
            IHead iHead = new IHead();
            iHead.setType("SJ");
            iHead.setUid(qmsmgMapper.uid());
            iHead.setTa001(moctyPlus.getTy001());
            iHead.setTa002(moctyPlus.getTy002());
            iHead.setTa004(moctyPlus.getProcessId());
            iHead.setTa024(moctyPlus.getProcessName());
            iHead.setTa006(moctyPlus.getProductId());
            iHead.setMb002(moctyPlus.getProductName());
            iHead.setMb003(moctyPlus.getSpecification());
            iHead.setTa015(new BigDecimal(moctyPlus.getTy004()));
            iHead.setCreatTime(TimeUtils.getFullNowTime());
            iHead.setUdf66(new BigDecimal(3D));
            iHead.setJinzhanUuid(jinzhanUuid);
//            iHead.setOrderNum(order);
//        iHead.setUdf88(new BigDecimal(3D));
            iHead.setMoctyudf05(uuid);
            iHead.setStatus(InspectStatusEnum.DaiJianYan.getValue());
            iHead.setUdf06(entry.getKey());
            iHead.setMacNo(resource.getDeviceid());
            iHead.setMacName(resource.getDevicename());
            iHead.setWorkCenterID(moctyPlus.getWorkCenterId());
            iHead.setWorkCenterName(moctyPlus.getWorkCenterName());

            com.example.entity.mysql.Resource device = resourceService.getOne(new LambdaQueryWrapper<com.example.entity.mysql.Resource>().eq(com.example.entity.mysql.Resource::getDeviceid, resource.getDeviceid()));
//            Cmsmx cmsmx = cmsmxService.getOne(new LambdaQueryWrapper<Cmsmx>().eq(Cmsmx::getMx001, resource.getDeviceid()));
            iHead.setMacPlaceID(device.getWorkCenter());
            Cmsmd cmsmd = cmsmdService.getOne(new LambdaQueryWrapper<Cmsmd>().eq(Cmsmd::getMd001, device.getWorkCenter()));
            iHead.setMacPlaceName(cmsmd.getMd002());
            iHead.setApprovalCode("N");
            iHead.setStatusCode("0");
            iHeadList.add(iHead);

            List<Qmsmg> list = entry.getValue();
            for(Qmsmg item : list) {
                IBody iBody = new IBody();
                iBody.setI_uid(iHead.getUid());
                BeanUtils.copyPropertiesIgnoreCase(item, iBody);
                iBodyList.add(iBody);
            }
//            System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());

//            // 消息通知
//            znxService.saveZnxAndSendMessage(MessageTypeEnum.JIANYAN.getValue(),
//                    "有一张首检单待处理, 单号：" + iHead.getUid(), ZnxStatusEnum.DAIBAN.getValue());

        }
        iHeadService.saveBatch(iHeadList);
        iBodyService.saveBatch(iBodyList);
//        Mocty mocty = new Mocty();  mocty.setUdf01(MOCStatusEnum.ShengChanZhong.getValue());  mocty.setUdf02(order.toString());
//        moctyMapper.update(mocty, new LambdaQueryWrapper<Mocty>().eq(Mocty::getUdf05, uuid));
        return 1;
    }

    @Override
    public AddFirstInspectionXianChangNoInsertVo addFirstInspectionXianChangNoInsert(String uuid, String jinzhanUuid, Long iheadUid) {

        MoctyPlus moctyPlus = moctyMapper.getMoctyPlus(uuid);
        QueryWrapper<Qmsmg> qmsmgQueryWrapper = new QueryWrapper<>();
        qmsmgQueryWrapper.eq("MG002", moctyPlus.getProductId());// 品号
        qmsmgQueryWrapper.eq("MG020", "首检"); //检验项目
//        qmsmgQueryWrapper.last("AND UDF06 = '现场'");
//        if (!StringUtils.isBlank(pojo.getRomm())){
//            qmsmgQueryWrapper.eq("UDF06", pojo.getRomm()); // 场地
//        }
        List<Qmsmg> qmsmgs = qmsmgMapper.selectList(qmsmgQueryWrapper);
        if (qmsmgs.isEmpty()) {  //没有首检项目，可直接上机
            return new AddFirstInspectionXianChangNoInsertVo(0, null, null);
        }

//        DynamicDataSourceContextHolder.push("mes");
        com.example.entity.mysql.Resource resource = resourceService.getOne(new LambdaQueryWrapper<com.example.entity.mysql.Resource>()
                .eq(com.example.entity.mysql.Resource::getResourceGroupIdIsF, moctyPlus.getTy009()));
        if(resource == null) {
            throw new CustomException("500", "机器不存在");
        }

//        DynamicDataSourceContextHolder.push("demo");
        Map<String, List<Qmsmg>> map = new HashMap<>();
        List<Qmsmg> qmsmgList = new ArrayList<>();
        for(Qmsmg t : qmsmgs) {
            qmsmgList.add(t);
        }
        map.put("现场", qmsmgList);
        List<IHead> iHeadList = new ArrayList<>();
        List<IBody> iBodyList = new ArrayList<>();
        for (Map.Entry<String, List<Qmsmg>> entry : map.entrySet()) {  // 按检验场别生成多张
            IHead iHead = new IHead();
            iHead.setType("SJ");
            iHead.setUid(iheadUid);
            iHead.setTa001(moctyPlus.getTy001());
            iHead.setTa002(moctyPlus.getTy002());
            iHead.setTa004(moctyPlus.getProcessId());
            iHead.setTa024(moctyPlus.getProcessName());
            iHead.setTa006(moctyPlus.getProductId());
            iHead.setMb002(moctyPlus.getProductName());
            iHead.setMb003(moctyPlus.getSpecification());
            iHead.setTa015(new BigDecimal(moctyPlus.getTy004()));
            iHead.setCreatTime(TimeUtils.getFullNowTime());
            iHead.setUdf66(new BigDecimal(3D));
            iHead.setJinzhanUuid(jinzhanUuid);
//            iHead.setOrderNum(order);
//        iHead.setUdf88(new BigDecimal(3D));
            iHead.setMoctyudf05(uuid);
            iHead.setStatus(InspectStatusEnum.DaiJianYan.getValue());
            iHead.setUdf06(entry.getKey());
            iHead.setMacNo(resource.getDeviceid());
            iHead.setMacName(resource.getDevicename());
            iHead.setWorkCenterID(moctyPlus.getWorkCenterId());
            iHead.setWorkCenterName(moctyPlus.getWorkCenterName());

            com.example.entity.mysql.Resource device = resourceService.getOne(new LambdaQueryWrapper<com.example.entity.mysql.Resource>().eq(com.example.entity.mysql.Resource::getDeviceid, resource.getDeviceid()));
//            Cmsmx cmsmx = cmsmxService.getOne(new LambdaQueryWrapper<Cmsmx>().eq(Cmsmx::getMx001, resource.getDeviceid()));
            iHead.setMacPlaceID(device.getWorkCenter());
            Cmsmd cmsmd = cmsmdService.getOne(new LambdaQueryWrapper<Cmsmd>().eq(Cmsmd::getMd001, device.getWorkCenter()));
            iHead.setMacPlaceName(cmsmd.getMd002());
            iHead.setApprovalCode("N");
            iHead.setStatusCode("0");
            iHeadList.add(iHead);

            List<Qmsmg> list = entry.getValue();
            for(Qmsmg item : list) {
                IBody iBody = new IBody();
                iBody.setI_uid(iHead.getUid());
                BeanUtils.copyPropertiesIgnoreCase(item, iBody);
                iBodyList.add(iBody);
            }
//            System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());

//            // 消息通知
//            znxService.saveZnxAndSendMessage(MessageTypeEnum.JIANYAN.getValue(),
//                    "有一张首检单待处理, 单号：" + iHead.getUid(), ZnxStatusEnum.DAIBAN.getValue());

        }

//        iHeadService.saveBatch(iHeadList);
//        iBodyService.saveBatch(iBodyList);
//        Mocty mocty = new Mocty();  mocty.setUdf01(MOCStatusEnum.ShengChanZhong.getValue());  mocty.setUdf02(order.toString());
//        moctyMapper.update(mocty, new LambdaQueryWrapper<Mocty>().eq(Mocty::getUdf05, uuid));
        return new AddFirstInspectionXianChangNoInsertVo(1, iHeadList, iBodyList);
    }

    public String SerialNumber(String ph) {
        QueryWrapper<Qmsmg> qmsmgQueryWrapper = new QueryWrapper<>();
        qmsmgQueryWrapper.orderByDesc("MG003");
        qmsmgQueryWrapper.eq("MG002",ph);
        //查询最新的流水号
        List<Qmsmg> sCells = qmsmgMapper.selectList(qmsmgQueryWrapper);
        //用于保存获取最新的流水号
        String temp="";
        //用于拼接需要的流水号
        String serialNumber="";
        //保存最新的流水号
        if(!sCells.isEmpty()){
            temp=sCells.get(0).getMG003();
        }
        //判断数据库是否有数据
        if (!StringUtils.isBlank(temp)){
            Integer integer=Integer.valueOf(temp.trim())+1;
            serialNumber=String.valueOf(integer);
        }else{
            serialNumber="1";
        }
        return serialNumber;
    }
    @Override
    public Boolean tc30IsN(String tc001, String tc002) {
        LambdaQueryWrapper<IHead> queryWrapper= new LambdaQueryWrapper<>();
        queryWrapper.eq(IHead::getType, tc001).eq(IHead::getUid, tc002);
        IHead iHead = iHeadMapper.selectOne(queryWrapper);
        if (iHead!=null&&iHead.getStatusCode().equals("0")){
            return true;
        }else {
            throw new BaseException(tc001+"-"+tc002+"该报价单不是未审核报价单");
        }
    }


}
